import java.util.ArrayList;
import java.util.Date;


public class SpecificFlight
{
	private Date date;
	private ArrayList<Booking> bookings;
	private RegularFlight regularFlight;
	
	public SpecificFlight(RegularFlight regularFlight, Date date)
	{
		this.regularFlight = regularFlight;
		this.date = date;
		this.bookings = new ArrayList<Booking>();
	}
	
	/**
	 * seatnumbers go from 0 to amountOfSeats
	 * this method is VERY inefficient
	 * @return seatNumber if there is a free seat else -1
	 */
	public int getFreeSeat()
	{		
		for(int i=0;i<this.regularFlight.getAmountOfSeats();i++)
		{
			boolean seatFree = true;
			
			for(int a=0;a<bookings.size();a++)
			{
				if(bookings.get(a).getSeatNumber() == i)
				{
					seatFree = false;
					break;
				}
			}
			
			if(seatFree)
			{
				return i;
			}
		}
		
		return -1;
	}
	
	/**
	 * Checks if a booking for a given passenger exists
	 * @param passenger
	 * @return if exists return the booking else return null
	 */
	public ArrayList<Booking> checkIfBookingExists(PassengerRole passenger)
	{
		ArrayList<Booking> bookingsTemp = new ArrayList<Booking>();
		
		for(int i=0;i<bookings.size();i++)
		{
			if(bookings.get(i).getPassenger().equals(passenger))
			{
				bookingsTemp.add(bookings.get(i));
			}
		}
		
		return (bookingsTemp.size() > 0) ? bookingsTemp : null;
	}
	
	public void addBooking(Booking booking)
	{
		bookings.add(booking);
	}
	
	public void deleteBooking(Booking booking)
	{
		bookings.remove(booking);
	}

	public void setDate(Date date)
	{
		this.date = date;
	}

	public Date getDate()
	{
		return date;
	}
}
